// 走马灯，轮播图
const mongoose = require('mongoose');

const carouselSchema = new mongoose.Schema(
  {
    title: {
      type: String,
      required: [true, 'carousel cannot be empty'],
      trim: true,
    },
    photo: {
      type: String,
      required: [true, 'carousel must have a photo'],
    },
    video: {
      type: mongoose.Schema.ObjectId,
      ref: 'Video',
      required: [true, 'carousel must belong to a Video'],
    },
  },
  {
    toJSON: { virtuals: true },
    toObject: { virtuals: true },
  }
);
carouselSchema.pre(/^find/, function (next) {
  this.populate({
    path: 'video',
    select: 'url',
  });
  next();
});
const Carousel = mongoose.model('Carousel', carouselSchema);

module.exports = Carousel;
